package com.aaa.mrcai.service.impl;

import com.aaa.mrcai.mapper.AreaMapper;
import com.aaa.mrcai.pojo.entity.Area;
import com.aaa.mrcai.pojo.entity.Emp;
import com.aaa.mrcai.pojo.entity.Location;
import com.aaa.mrcai.pojo.entity.State;
import com.aaa.mrcai.pojo.vo.AreaStateVO;
import com.aaa.mrcai.pojo.vo.AreaVO;
import com.aaa.mrcai.query.AreaQuery;
import com.aaa.mrcai.result.AjaxResult;
import com.aaa.mrcai.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.HashMap;
import java.util.List;

/**
 * @author meowyf
 * @version 1.0
 * @Name Z_MJ
 * @date 2021/12/05 18:18:52
 */
@Service
public class AreaServiceImpl implements AreaService {
    @Autowired
    private AreaMapper areaMapper;


    @Override
    public AjaxResult list(AreaQuery areaQuery) {
        List<Area> i = areaMapper.list(areaQuery);
        Long totalCount = areaMapper.queryAreaTotalCount(areaQuery);

        HashMap<Object, Object> map = new HashMap<>();
        map.put("areaListAll",i);
        map.put("areaNumber",totalCount);
        return AjaxResult.success(map);
    }

    @Override
    public AjaxResult listState() {
        List<State> stateList = areaMapper.listState();
        return AjaxResult.success(stateList);
    }

    @Override
    public AjaxResult location() {
        List<Location> i = areaMapper.location();
        return AjaxResult.success(i);
    }

    @Override
    public AjaxResult admin() {
        List<Emp> admin = areaMapper.admin();
        return AjaxResult.success(admin);
    }

    @Override
    public AjaxResult addArea(AreaVO areaVO) {
        int i = areaMapper.addArea(areaVO);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.defeated();
    }

    @Override
    public AjaxResult updateState(AreaStateVO areaStateVO) {
        if (areaStateVO.getState()!="0") {
            int i = areaMapper.updateState(areaStateVO);
            return AjaxResult.success();
        }
        return AjaxResult.defeated();
    }

    @Override
    public AjaxResult updateStateTWO(AreaStateVO areaStateVO) {
        if (areaStateVO.getState()!="1") {
            int i = areaMapper.updateStateTWO(areaStateVO);
            return AjaxResult.success();
        }
        return AjaxResult.defeated();
    }


}
